﻿using Microsoft.AspNetCore.Mvc;
using UpperComputer.Application;
using UpperComputer.Web.Entry.Models;
using YFurion.Application;
using YFurion.Controllers;

namespace UpperComputer.Web.Entry.Controllers
{
    /// <summary>
    /// 菜单按钮控制器
    /// </summary>
    [ApiDescriptionSettings(ApiGroupConst.USER_AUTHORIZATION)]
    public class MenuButtonController : AuthorizeController
    {
        private readonly IBaseMenuButtonService _baseMenuButtonService;
        private readonly IBaseMenuService _baseMenuService;

        /// <summary>
        /// 菜单按钮控制器构造函数
        /// </summary>
        /// <param name="baseMenuButtonService">菜单按钮服务</param>
        /// <param name="baseMenuService">菜单服务</param>
        public MenuButtonController(
            IBaseMenuButtonService baseMenuButtonService,
            IBaseMenuService baseMenuService)
        {
            _baseMenuButtonService = baseMenuButtonService;
            _baseMenuService = baseMenuService;
        }

        /// <summary>
        /// 获取菜单按钮集合
        /// </summary>
        /// <param name="baseMenuButtonResultRequestDto"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<BaseMenuButtonResultDto>> Get([FromQuery] BaseMenuButtonResultRequestDto baseMenuButtonResultRequestDto)
        {
            PagedResultDto<BaseMenuButtonResultDto> bserMenuButtonResult = await _baseMenuButtonService.GetCustomAll(baseMenuButtonResultRequestDto);
            return bserMenuButtonResult;
        }

        /// <summary>
        /// 根据ID获取菜单按钮
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<BaseMenuButtonResultDto> Get(long id)
        {
            BaseMenuButtonResultDto baseMenuButtonResult = await _baseMenuButtonService.Get(id);
            return baseMenuButtonResult;
        }

        /// <summary>
        /// 获取菜单集合
        /// </summary>
        /// <param name="baseMenuResultRequestDto"></param>
        /// <returns></returns>
        public async Task<List<BaseMenuResultDto>> GetMenus([FromQuery] BaseMenuResultRequestDto baseMenuResultRequestDto)
        {
            baseMenuResultRequestDto.MaxResultCount = int.MaxValue;
            baseMenuResultRequestDto.IsActive = true;
            List<BaseMenuResultDto> baseMenuResultDtos = await _baseMenuService.GetMenus(baseMenuResultRequestDto);
            return baseMenuResultDtos;
        }

        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<BaseMenuButtonResultDto> Post(BaseMenuButtonDto dto)
        {
            BaseMenuButtonResultDto entityDto = await _baseMenuButtonService.Post(dto);
            return entityDto;
        }

        /// <summary>
        /// 克隆按钮
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [YUnitOfWork]
        public async Task<List<BaseMenuButtonResultDto>> CopyButton(MenuButtonCopyInputModel input)
        {
            List<BaseMenuButtonResultDto> entityDto = await _baseMenuButtonService.Copy(input.BaseMenuButtonDtos);
            return entityDto;
        }

        /// <summary>
        /// 修改按钮
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<BaseMenuButtonResultDto> Put(BaseMenuButtonDto dto)
        {
            BaseMenuButtonResultDto entityDto = await _baseMenuButtonService.Put(dto);
            return entityDto;
        }

        /// <summary>
        /// 删除按钮
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<EntityDto> Delete(long id)
        {
            await _baseMenuButtonService.Delete(id);
            return new EntityDto { Id = id };
        }
    }
}
